package com.example.hospital.mapper;



import com.example.hospital.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
/*用户mapper接口*/
@Mapper
public interface UserMapper {

    @Select("select * from user where username = #{username}")
    User findByUsername(String username);

    @Select("select * from user where id = #{id}")
    User findById(Integer id);

    @Select("select * from user where role = #{role}")
    List<User> findByRole(String role);

    @Insert("insert into user(username, password, role, email, phone, created_at, updated_at) " +
            " values (#{username}, #{password}, #{role}, #{email}, #{phone}, now(), now())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insertUser(User user);

    @Update("update user set username=#{username}, password=#{password}, role=#{role}, " +
            "email=#{email}, phone=#{phone}, updated_at=now() where id=#{id}")
    void updateUser(User user);

    @Delete("delete from user where id=#{id}")
    void deleteUser(Integer id);

    @Select("select * from user")
    List<User> findAll();
}
